import { install } from "element-plus";
//导入useIntersectionObserver
import { useIntersectionObserver } from '@vueuse/core'

//定义懒加载插件
export const lazyPlugin = {
    install(app) {
        //定义全局指令
        app.directive('img-lazy', {
            mounted(el, binding) {
                //el:指令绑定的真实dom元素 img
                //binding:binding.value  指令等于后面绑定的表达式的值 图片的url
                // console.log(el, binding.value);
                const { stop } = useIntersectionObserver(
                    el,
                    ([{ isIntersecting }]) => {
                        // console.log(isIntersecting)
                        if (isIntersecting) {
                            el.src = binding.value
                            stop()
                        }
                    },
                )



            }
        })
    }
} 